﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimScripts.BF4Rcon.Resources;

namespace TimScripts.BF4Rcon
{
    public enum PlayerSubsetType
    {
        Unknown,
        All,
        Team,
        Squad,
        Player
    }

    public class PlayerSubset
    {
        public PlayerSubsetType SubsetType { get; private set; }

        private int _TeamId;
        public int TeamId
        {
            get
            {
                if (SubsetType != PlayerSubsetType.Team && SubsetType != PlayerSubsetType.Squad)
                    throw new InvalidOperationException(ErrorStrings.InvalidOperation_PlayerSubsetTeamId);

                return _TeamId;
            }

            private set { _TeamId = value; }
        }

        private int _SquadId;
        public int SquadId
        {
            get
            {
                if (SubsetType != PlayerSubsetType.Squad)
                    throw new InvalidOperationException(ErrorStrings.InvalidOperation_PlayerSubsetSquadId);

                return _SquadId;
            }

            private set { _SquadId = value; }
        }

        private Player _Player;
        public Player Player
        {
            get
            {
                if (SubsetType != PlayerSubsetType.Player)
                    throw new InvalidOperationException(ErrorStrings.InvalidOperation_PlayerSubsetPlayer);

                return _Player;
            }

            private set { _Player = value; }
        }

        public static PlayerSubset CreateAll()
        {
            return new PlayerSubset(PlayerSubsetType.All);
        }

        public static PlayerSubset CreateTeam(int teamId)
        {
            return new PlayerSubset(PlayerSubsetType.Team, teamId);
        }

        public static PlayerSubset CreateSquad(int teamId, int squadId)
        {
            return new PlayerSubset(PlayerSubsetType.Squad, teamId, squadId);
        }

        public static PlayerSubset CreatePlayer(Player player)
        {
            return new PlayerSubset(PlayerSubsetType.Player, player: player);
        }

        public static PlayerSubset CreateUnknown()
        {
            return new PlayerSubset(PlayerSubsetType.Unknown);
        }

        private PlayerSubset(PlayerSubsetType type, int teamId = 0, int squadId = 0, Player player = null)
        {
            SubsetType = type;
            Player = player;
            TeamId = teamId;
            SquadId = squadId;
        }
    }
}
